<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1.可选操作符合; ?
        let obj = {
            name : '张三',
            obj1 :{
               myname : '李四', 
            }
        }

        // console.log(obj.age);// undfiend
        // console.log(obj.obj2.age); // 报错

        // if(typeof obj.obj2 !== undefined){
        //     console.log(obj.obj2.age);
        // }

        // console.log(obj?.obj2?.age);//undfiend



        // 2.空合并运算符 ??  // 它会把"" 和 0 当为true看

        function fn(a,b){
            // var a = a || 1;
            // var b = b || 2;
            var a = a ?? 1;
            var b = b ?? 2;

            console.log(a,b);
        }
        fn("",0); // 空 , 0
        fn(3,4);  // 3 , 4
        fn(undefined,null) // 1 , 2










    </script>
</body>
</html>